// Anodem-L.h
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef enum {
    FALSE,
    TRUE,
} BOOL;
unsigned tkbg,tknd;
void next(const char*rcode) {
    tkbg=tknd+1;
	char fspc=1;
    unsigned i;
	for(i = tkbg; i < strlen(rcode); i++) {
		if(rcode[i]=='>'&&rcode[i-1]!='@') {
			tknd=i;
			break;
		} else if((rcode[i]==' '||rcode[i]=='\n'||rcode[i]=='\t')&&fspc) {
			++tkbg;
		} else {
			fspc=0;
		}
	}
	if(tkbg==1) tkbg--;
    return ;
}
char*substr(const char*str,int beg,int end) {
	char*sub=(char*)malloc((end-beg+1)*sizeof(char));
	for(unsigned i = 0; i<(end-beg+1); i++) {
		sub[i]=str[i+beg];
	}
	return sub;
}
void parse(const char*rcode) {
    char*alab=(char*)malloc(20*sizeof(char*)),*script=(char*)malloc(1024*sizeof(char*));
    unsigned i;
    do {
        next(rcode);
        sscanf(substr(rcode,tkbg,tknd),"%[^:]",alab); // simp-regexp
		for(i = tkbg+strlen(alab); ; i++) {
			if(rcode[i]=='<') {
			    strcpy(script,substr(rcode,i+1,tknd-1));
			    for(i=0; i<strlen(script)-1; i++) {
			        if(script[i]=='@'&&script[i+1]=='>') {
			            script[i]=21;
			        }
			    }
				printf("Label:  %s ; \nScript: %s\n\n",alab,script);
				break;
			}
		}
		if(!strcmp(alab,"@End")) break;
    } while(TRUE);
    return ;
}